﻿using System;

/// <summary>
/// 定时任务管理器
/// </summary>
public class TimerManager:MonoSingleton< TimerManager >
{ 
    private Timer timer;

    protected override void Awake()
    {
        base.Awake();
        instance = this;

        timer = new Timer();
    } 
    void Update()
    {
        timer.Update();
    }

    /// <summary>
    /// 添加定时任务
    /// </summary>
    /// <param name="callBack"></param>
    /// <param name="delay"></param>
    /// <param name="doCount"></param>
    /// <param name="unit"></param>
    /// <returns></returns>
    public int AddTimerTask(Action callBack,double delay,int doCount=1,TimeUnit unit=TimeUnit.MS)
    {
        return timer.AddTimerTask(callBack, delay, doCount, unit);
    } 
    /// <summary>
    /// 直接删除定时任务
    /// </summary>
    /// <param name="tid"></param>
    public void DelTiemrTask(int tid)
    {
        timer.DelTimerTask(tid);    
    }
    /// <summary>
    /// 通过Tid替换定时任务
    /// </summary>
    /// <param name="tid"></param>
    /// <param name="callBack"></param>
    /// <param name="delay"></param>
    /// <param name="doCount"></param>
    /// <param name="unit"></param>
    public bool RetTimerTask(int tid,Action callBack,double delay,int doCount=1,TimeUnit unit = TimeUnit.MS)
    {
        return timer.ReplaceTimer(tid, callBack, delay, doCount, unit);
    }
}